package spring.cloud.tasks.tasks_manager.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import spring.cloud.tasks.tasks_manager.mapper.TaskInstanceMapper;
import spring.cloud.tasks.tasks_manager.schedule.TaskInstanceInfo;

import java.util.List;

@Slf4j
public class TaskInstanceService {
    private TaskInstanceMapper taskInstanceMapper;

    @Transactional
    public boolean add(TaskInstanceInfo taskInstanceInfo) {

        try {
            taskInstanceMapper.add(taskInstanceInfo);
            return true;
        } catch (Throwable e) {
            log.error("添加任务实例信息列表失败:" + e.getMessage(), e);
            return false;
        }
    }

    @Transactional
    public boolean batchAdd(List<TaskInstanceInfo> taskInstanceInfoList) {
        try {
            taskInstanceMapper.batchAdd(taskInstanceInfoList);
            return true;
        } catch (Throwable e) {
            log.error("批量添加任务实例信息列表失败:" + e.getMessage(), e);
            return false;
        }
    }
}
